package com.wyfx.blockchain.common;

import com.wyfx.blockchain.common.exception.BaseException;
import com.wyfx.blockchain.common.response.ResultResponse;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletResponse;

/**
 * @Description
 * @Auther: wsm
 * @Date: 2020/9/4 20:43
 */
@RestControllerAdvice
public class BaseExceptionHandler {

    @ExceptionHandler(value = BaseException.class)
    public ResultResponse globalException(BaseException e) {
        return new ResultResponse(5001, e.getMessage());
    }

    @ExceptionHandler(value = Exception.class)
    public ResultResponse systemException(Exception e) {
        return new ResultResponse(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
    }
}
